// <<<<<<< HEAD
// //category统一判断
// // category=701;
// // server_parameter.id="-1";
// =======
// >>>>>>> 7bf0624e0fd6dc54d71547805a03ab6ac9df700d

if (category == 100) {//首页 return
    } else if (category == 201) {//中心负责人介绍
        console.log("123");
        get_Expert_Detail(30);
    } else if (category == 202 || category == 203 || category == 204 ||
        category == 205 || category == 401 || category == 703 || category == 900) {
        //202中心介绍；203学术委员会；204组织架构；205历史沿革；401研究方向；703规章制度；900联系我们。这一部分的category是只有一个详情页的，用category参数取数据
        getInfo(category)
        //进入文章详情页
    } else if (category == 301) {//301杰出人才 return "front/front_team"
        getExpertTeam(1)
    } else if (category == 302) {//302PI人员； 303研究团队 ；return"front/front_expert"
        getExpert(2)
    } else if (category == 303) {
        //循环获取 单独的处理逻辑
        getExpert(2)
    }

    else if (category == 402) {//科研成果； return "front/front_achievement"

    } else {//304学生培养；403学科建设；404开放基金；500科研平台；600交流动态；
        //701中心新闻；702通知公告；704下载中心；802博1英才招聘；80士后招聘； return "front/front_catalog"
        if (server_parameter.id == "-1") {
            getlist(category, 1)
        } else {
            console.log(server_parameter.id);
            getDetail(server_parameter.id)
        }
    }






//catalog数据
function getlist(category, nowpage) {
    $.ajax({
        url: "http://118.178.195.213:4399/api/article/list",
        type: "get",
        data: {
            category: category,
            currentPage: nowpage,
            // pageSize: 9,
        },
        dataType: "json",
        success: function (d) {
            console.log("list", d);
            rdPageBtn(d.allPages, category, nowpage)
            $("#cultureStudent_top").empty()
            var ul = $("<ul></ul>");
            for (var i = 0; i < d.datas.length; i++) {
                var user = d.datas[i];
                var li = "<li class=\"fix\">" + "<pre>" + "<a href=\"/front/route/article/detail?category=" + category + "&id=" + user.id + " \" target=\"_top\">" + user.title + "<a>" + "                              " +
                    "<span>" + user.createTime + "</span>" + "</pre>" + "</li>";
                //将li元素设置到ul元素里面
                ul.append(li);
            }
            console.log(ul);
            $("#cultureStudent_top").append(ul)
            $(".pagebtn").removeClass("on")
            $(".pagebtn").eq(nowpage - 1).addClass("on")
        }

    })

}
//分页的渲染
function rdPageBtn(all_pages, category, nowpage) {
    // <a class="p_first" href="https://skl.ustb.edu.cn/xwzx/tzgg/index.htm">首页</a>
    // <a class="p_prev" href="https://skl.ustb.edu.cn/xwzx/tzgg/index.htm">上一页</a>
    // <a class=" on pagebtn">1</a>
    // <a class="pagebtn" onclick="getlist(2)">2</a>
    // <a class="pagebtn" onclick="getlist(3)">3</a>
    // <a class="p_next" href="https://skl.ustb.edu.cn/xwzx/tzgg/index1.htm">下一页</a>
    // <a class="p_last" href="https://skl.ustb.edu.cn/xwzx/tzgg/index2.htm">尾页</a>
    $(".paginga").empty()
    $(".paginga").append("<a class=\"p_first\" onclick=\"getlist(" + category + ",1)\">首页</a>")
    $(".paginga").append("<a class=\"p_prev\" onclick=\"getlist(" + category + "," + ((nowpage - 1) < 1 ? 1 : (nowpage - 1)) + ")\">上一页</a>")//字符串拼接中变量的拼接+
    for (var i = 1; i <= all_pages; i++) {
        $(".paginga").append("<a class=\"pagebtn\" onclick=\"getlist(" + category + "," + (i) + ")\">" + (i) + "</a>")
    }
    $(".paginga").append("<a class=\"p_next\" onclick=\"getlist(" + category + "," + ((nowpage + 1) > all_pages ? all_pages : (nowpage + 1)) + ")\">下一页</a>")//添加字符串加双引号
    $(".paginga").append("<a class=\"p_first\" onclick=\"getlist(" + category + "," + (all_pages) + ")\">尾页</a>")
}



//essay渲染
//category获取数据
function getInfo(category) {
    $.ajax({
        url: "http://118.178.195.213:4399/api/article/latest/category",
        type: "get",
        data: {
            category: category
        },
        dataType: "json",
        success: function (d) {
            console.log(d);
            var title = d.datas[0].title;
            var author = d.datas[0].author;
            var createTime = d.datas[0].createTime;
            var content = d.datas[0].content;
            var p1 = "<h3  style=\"text-align:center;\">" + title + "</h3>";
            $("#newsXq_top").append(p1)
            var p2 = "<pre>" + "作者:" + "<span>" + author + "</span>" + "                                                                                        " + "时间:" + "<span>" + createTime + "</span>" + "</pre>";
            $("#newsXq_top").append(p2)
            var p3 = "<p style=\"LINE-HEIGHT: 180%; text-indent: 2em; font-size: 14pt;\" status=\"mid\">" + "<span style=\"font-size: 16px;\">" + content + "</span>" + "</p>";
            $("#newsXq_bom").append(p3)
        }
    })

}
function getDetail(id) {
    // detail id获取文章详情
    $.ajax({
        url: "http://118.178.195.213:4399/api/article/detail",
        type: "get",
        data: {
            id: id
        },
        dataType: "json",
        success: function (d) {
            console.log(d);
            var title = d.datas[0].title;
            var author = d.datas[0].author;
            var createTime = d.datas[0].createTime;
            var content = d.datas[0].content;
            var p1 = "<h3  style=\"text-align:center;\">" + title + "</h3>";
            $("#newsXq_top").append(p1)
            var p2 = "<pre>" + "作者:" + "<span>" + author + "</span>" + "                                                                                        " + "时间:" + "<span>" + createTime + "</span>" + "</pre>";
            $("#newsXq_top").append(p2)
            var p3 = "<p style=\"LINE-HEIGHT: 180%; text-indent: 2em; font-size: 14pt;\" status=\"mid\">" + "<span style=\"font-size: 16px;\">" + content + "</span>" + "</p>";
            $("#newsXq_bom").append(p3)
        }
    })
};




//expert数据
function getExpert(classId) {
    $.ajax({
        url: "http://118.178.195.213:4399/api/person/list/class",
        type: "get",
        data: {
            classId: classId
        },
        dataType: "json",
        success: function (d) {
            console.log(d);
            for (var i = 0; i < d.datas[0].workTitles.length; i++) {
                var a = d.datas[0].workTitles[i];
                console.log(a);
                var tr = "<tr>"
                var td1 = "<td>" + "<b>" + a.titleName + "</b>" + "</td><td>"
                var td2 = ""
                for (var j = 0; j < a.persons.length; j++) {
                    td2 += "<span>" + "<a href=\"#\" target=\"_blank\">" + a.persons[j].name + "</a>" + "</span>"
                }
                tr += td1 + td2 + "</td></tr>"
                $("#expert-table").append(tr)//tr为存着字符串的变量不需要双引号
            }
        }
    })
}

//expertteam数据
function getExpertTeam(classId) {
    $.ajax({
        url: "http://118.178.195.213:4399/api/person/list/class",
        type: "get",
        data: {
            classId: classId
        },
        dataType: "json",
        success: function (d) {
            console.log(d);
            for (var i = 0; i < d.datas[0].workTitles.length; i++) {
                var a = d.datas[0].workTitles[i].persons.length;
                console.log(a);
                var tr1 = "<tr>" + "<td rowspan=\"" + a + "\" >" + "<b>" + d.datas[0].workTitles[i].titleName + "<b>" + "</td>"
                    + "<td>" + d.datas[0].workTitles[i].persons[0].name + "</td>"
                    + "<td>" + d.datas[0].workTitles[i].persons[0].telPhone + "</td>"
                    + "<td>" + d.datas[0].workTitles[i].persons[0].jobTitle + "</td>"
                    + "<td>" + d.datas[0].workTitles[i].persons[0].email + "</td>"
                    + "</tr>";
                $("#team-table").append(tr1);
                for (var j = 1; j < d.datas[0].workTitles[i].persons.length; j++) {
                    var tr2 = "<tr>" + "<td >" + d.datas[0].workTitles[i].persons[j].name + "</td>"
                        + "<td>" + d.datas[0].workTitles[i].persons[j].telPhone + "</td>"
                        + "<td>" + d.datas[0].workTitles[i].persons[j].jobTitle + "</td>"
                        + "<td>" + d.datas[0].workTitles[i].persons[j].email + "</td>"
                        + "</tr>";
                    $("#team-table").append(tr2);
                }
            }

        }
    })
}



//专家详情页
// <!-- <h3 class="wenZi" status="mid">夏秀芹</h3>
// <p class="wenZi" status="mid">党委书记 </p>
// <span class="wenZi" status="mid">电话：010-62332595</span>
// <span class="wenZi" status="mid">办公室：主楼290-1</span>
// <span class="wenZi" status="mid">传真：010-62333447</span>
// <span class="wenZi" status="mid">职称：副研究员</span>
// <span class="wenZi" status="mid">Email：xiaxiuqin@ustb.edu.cn</span> -->
function get_Expert_Detail(personid) {
    $.ajax({
        url: "http://118.178.195.213:4399/api/person/detail",
        type: "get",
        data: {
            id: personid
        },
        dataType: "json",
        success: function (d) {
            console.log(d);
            $("#pic").append("<img src='http://118.178.195.213:4399"+d.datas[0].picture+" ' style='width: 154px;height: 205px;'>");

            $("#detail").append("<h3 class='wenZi' status='mid'>"+d.datas[0].name+"</h3>");
            $("#detail").append(" <span class='wenZi' status='mid'>电话："+d.datas[0].telPhone+"</span>");
            $("#detail").append(" <span class='wenZi' status='mid'>职称："+d.datas[0].jobTitle+"</span>");
            $("#detail").append(" <span class='wenZi' status='mid'>Email:"+d.datas[0].email+"</span>");

            $("#introduce").append(d.datas[0].introduce)
        }
    })
}
